﻿using UnityEngine;
using System.Collections;
using ASFU;
using UnityEngine.UI;
using flash.display;
using flash.text;
using flash.events;

public class Demo : MonoBehaviour 
{
	public Font font;
	private ScriptObject stage;
	private Stage cstage;
	void Start()
	{
		StartAS3();
//		StartCShap();
	}
	void StartAS3()
	{
		Util.Init();		
		Util.PushAssembly(typeof(int).Assembly);
		Util.PushAssembly(typeof(GameObject).Assembly);
		Util.PushAssembly(typeof(Text).Assembly);
		Util.PushAssembly(GetType().Assembly);
		Util.RegFromDirectory(Application.streamingAssetsPath,"AS3");
		Util.RegFromDirectory(Application.streamingAssetsPath,"src");
		ScriptClass Stage = Util.GetClass("flash.display.Stage");
		Stage.GetValue("init").Call(new ScriptObject[]{Util.CreateNumber(960),Util.CreateNumber(640)});//调用Stage的init方法
		Stage.SetValue("font",Util.CreateObject(font));//设置Stage的font属性
		ScriptASObject textField = Util.Run("Test");//实例化Test类
		stage = Stage.GetValue("stage");//获取舞台对象
		Util.GetValue(stage,"addChild").Call(new ScriptObject[]{textField});//把test添加到舞台
	}
	void StartCShap ()
	{
		cstage = Stage.Init();
		Stage.font = font;
		TextField text = new TextField();
		text.text = "c#创建的文本框";
		text.AddEventListener(MouseEvent.RIGHT_MOUSE_DOWN,OnRightMouseDown);
		DisplayObjectContainer displayObjectContainer = new DisplayObjectContainer();
		displayObjectContainer.addChild(text);
		cstage.addChild(displayObjectContainer);
	}
	void OnRightMouseDown(flash.events.Event mouseEvent)
	{
		Debug.Log("鼠标右键按下");
	}
	void Update ()
	{
		Util.GetValue(stage,"render").Call();
//		cstage.Render();
	}
}
